﻿namespace WMS6.Web.CrossDock
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CrossdockServiceRef;

    public class FlowThruAllocationDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected CheckBox chkAllowOverShipment;
        protected HtmlForm F79623;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnOwnerID;
        protected HtmlHead Head1;
        protected HtmlImage imgOwnerID;
        protected Label lblAllocateRuleDetail;
        protected Label lblMaximumPerOver;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblSeqNo;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtCustomerID;
        protected TextBox txtMaximumPerOver;
        protected TextBox txtSeqNo;
        protected UpdatePanel up1;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("FlowThruApportionmentRule.aspx?from={0}&detail={1}&ID={2}", this.hdnFrom.Value, "1", base.Server.UrlEncode(this.hdnOwnerID.Value)));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtCustomerID.Text.Trim()))
            {
                this.lblMsg.Text = "请输入客户!";
            }
            else if (string.IsNullOrEmpty(this.txtSeqNo.Text.Trim()))
            {
                this.lblMsg.Text = "请输入序号!";
            }
            else
            {
                bool success = false;
                try
                {
                    ApportionRuleInfo apportionRuleInfo = new ApportionRuleInfo {
                        OwnerID = this.hdnOwnerID.Value,
                        CustomerID = this.txtCustomerID.Text.Trim(),
                        SeqNo = int.Parse(this.txtSeqNo.Text.Trim()),
                        MaximumPerOver = decimal.Parse(this.txtMaximumPerOver.Text.Trim()),
                        AllowOverShipment = this.chkAllowOverShipment.Checked ? "Y" : "N",
                        CreatedBy = base.UserInfo.UserID,
                        CreatedDate = DateTime.Now
                    };
                    if (!string.IsNullOrEmpty(CrossdockServiceClientProxy.GetInstance().InsertApportionRuleInfo(apportionRuleInfo)))
                    {
                    }
                    success = true;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = "直通分配规则明细添加失败" + ex.Message;
                    return;
                }
                if (success)
                {
                    base.Response.Redirect(string.Format("FlowThruApportionmentRule.aspx?from={0}&detail={1}&ID={2}", this.hdnFrom.Value, "1", base.Server.UrlEncode(this.hdnOwnerID.Value)));
                }
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"].ToString()))
            {
                string from = base.Request.QueryString["from"].ToString();
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"].ToString()))
            {
                string OwnerID = base.Request.QueryString["ID"].ToString();
                this.hdnOwnerID.Value = OwnerID;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }
    }
}

